package com.fbee.smartcommunities.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fbee.smartcommunities.entity.Permission;
import com.fbee.smartcommunities.entity.RolePermission;
import com.fbee.smartcommunities.service.PermissionService;
import com.fbee.smartcommunities.service.RolePermissionService;
import com.fbee.smartcommunities.vo.ResultVO;
import com.fbee.smartcommunities.vo.RolePermissionVO;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 调整AUTO_INCREMENT值 前端控制器
 * </p>
 *
 * @author 汪佳泉
 * @since 2024-08-16
 */
@RestController
@RequestMapping("/rolePermission")
public class RolePermissionController {

    @Resource
    private PermissionService permissionService;
    
    @Resource
    private RolePermissionService rolePermissionService;

    @GetMapping("/getData")
    public ResultVO<RolePermissionVO> getData(Long roleId){
        List<RolePermission> rolePermissionList = rolePermissionService.list(new QueryWrapper<RolePermission>().eq("role_id", roleId).eq("type",0));
        List<Permission> sysPermissionList = permissionService.getlist();
        return ResultVO.success(new RolePermissionVO(rolePermissionList,sysPermissionList));
    }

    @PostMapping("/add")
    public ResultVO<Boolean> add(Long []PermissionIds,Boolean[] PermissionTypes,Long roleId){
        return ResultVO.success(rolePermissionService.add(PermissionIds,PermissionTypes,roleId),"权限绑定成功");
    }


    
}
